<!doctype html>
<html>

	<head>
		<meta charset="UTF-8">
		<title></title>
		<meta name="viewport" content="width=device-width,initial-scale=1,minimum-scale=1,maximum-scale=1,user-scalable=no" />
		<link href="../css/mui.min.css" rel="stylesheet" />
		<link rel="stylesheet" href="../css/picker.css" />
		<link rel="stylesheet" href="../css/poppicker.css" />
		<link rel="stylesheet" type="text/css" href="../css/style.css" />
		<link rel="stylesheet" type="text/css" href="../css/datepicker3.css" />
		<link rel="stylesheet" href="../css/member.css" />

	</head>

	<body>
		<header class="mui-bar mui-bar-nav public-color">
			<a id="shan" class="mui-action-back mui-icon mui-icon-left-nav mui-pull-left"></a>
			<h1 class="mui-title">产品发布</h1>
			<!--//<button class="mui-pull-right edit" id="btn" style="background-color: #ff7831;border: 0px;color: #efecec; font-size: 16px;">保存</button>-->
		</header>
		<div class="mui-content address_content">
			<form class="mui-input-group">
				<div class="mui-input-row ">
					<label>产品名：</label>
					<input type="text"  id="name"  class="mui-input-group" >
				</div>
				<div class="mui-input-row">
					<label>售价：</label>
					<input type="text" id="price" class="mui-input-group" >
				</div>
				<div class="mui-input-row">
					<label>分类：</label>
					<select id='type' onchange="func(this.value)">
					<option value="">请选择分类</option>							
					</select>
				</div>
				<div class="mui-input-row">
					<label>子分类：</label>
					<select id='ztype' >
						<option value='' >请选择分类</option>
					</select>
				</div>
				<div class="mui-input-row">
					<label>单位：</label>
					<input type="text" id="unit"  class="mui-input-group" >
				</div>
				<div class="mui-input-row">
					<label>预产量：</label>
					<input type="text" id="num" class="mui-input-group" >
				</div>
				<div class="mui-input-row">
					<label>生产时间 ：</label>
					<input type="text" name="birthday" id="cr_time" class="datetimepicker" id="datetimepicker">
				</div>
				<div class="mui-input-row">
					<label>生产地址 ：</label>
					<input type="text" id="district" readonly="readonly" class="mui-input-group" placeholder="请选择地区">
				</div>
			</form>
			<div class="address_mor clearfix">
				<label class="col-sm-3 control-label">图文详情：</label>
					<strong>默认第一张主图</strong>
					<form class="mui-input-group gerenzl_group">
					<div class="gerenzl_top img-click">
						<div class="actions">
							<button class="file-btn" style="width: 60%; height: 30px;">
				               <span style="font-size: 12px;width: 60%;">上传图片</span>
				                <input type="file" id="upload" value="选择图片文件" multiple/>
				           </button>
				           <hr>
							<div id="img_list" class="img_list">
								
							</div>
						</div>
						
					</div>					
				</form>																			<div class="gerzl_btn" id="btn" onclick="func1()">
					<a href="#">发布</a>
			</div>
		</div>
		<input type="hidden" id='order_ids'>
		<script type="text/javascript" src="../js/jquery.min.js"></script>
		<script type="text/javascript" src="../js/bootstrap-datepicker.js"></script>
		<script src="../js/layer/layer.min.js"></script>
		<script src="../js/mui.min.js"></script>
		<script src="../js/castapp.js"></script>
		<script src="../js/picker.js"></script>
		<script src="../js/poppicker.js"></script>
		<script src="../js/city.data-3.js"></script>
		<script src="../js/app.js"></script>
		<script src="../js/ueditor/ueditor.config.js" type="text/javascript"></script>
		<script src="../js/ueditor/ueditor.all.js" type="text/javascript"></script>
		<script>
				//编辑器
			var member=JSON.parse(localStorage.getItem('member'));		
	$(function () {
dlpd();
			ca.init();
    		var dis = ca.id('district');
			dis.addEventListener('tap', function() {
				//三级组合
				castapp.combinationSelect(3, cityData3, function(arr) {
					dis.value = arr;
				});
			});		
		        $(".datetimepicker").datepicker({
		            language: "zh-CN",
		            autoclose: true,//选中之后自动隐藏日期选择框
		            clearBtn: true,//清除按钮
		            todayBtn: true,//今日按钮
		            format: "yyyy-mm-dd"//日期格式，详见 http://bootstrap-datepicker.readthedocs.org/en/release/options.html#format
		        });
				$('#upload').on('change', function() {
					readFile(this,"thumb",1,10);
				});
				
		//获取分类
		$.ajax({
		type:"post",
		url:APP.api_url + "goods/get_type",
		data:{
		},
		dataType:'jsonp',
		success:function(data){
			var type=data.list;
			for(var i=0;i<type.length;i++){
				$('#type').append('<option value='+type[i]['id']+'>'+type[i]['typename']+'</option>');
				}			
			},	
		});
	});
    	//及时获取子分类
	function func(val){
		$('#ztype').empty();
		$('#ztype').show();
		$.ajax({
		type: "post",
		url: APP.api_url + "goods/get_type",
		data: {
			id:val
		}, 
		dataType: 'jsonp',
		success: function(data) {
			if(data.code==200){
				var type = data.list;
			for(var i = 0; i < type.length; i++) {
				$('#ztype').append('<option  value=' + type[i]['id'] + '>' + type[i]['typename'] + '</option>');
				}
			}else {
				$('#ztype').hide();				
			}
		},
	});
	}

$("#shan").click(function() {
		location.href = "spedit.html";
	});
		//获取传过来的图片
function func1(){
var x=document.getElementsByName("pic_d");	
			var pic_d="";
			var images="";
			for(var i=0 ;i<x.length;i++){
				if(i==0){
					images+=x[i].value;
					pic_d+=x[i].value;
				}else{
					pic_d+='@'+x[i].value;
				}				
			}
		if($("#name").val() == ''){
			layer.msg('产品名称不能为空', {icon: 1,time:1500,shade: 0.1})
			return false;
		}
		if($("#type").val() == ''){
			layer.msg('请选择分类', {icon: 1,time:1500,shade: 0.1})
			return false;
		}
		if($('#price').val() == ''){
			layer.msg('售价不能为空', {icon: 1,time:1500,shade: 0.1})
			return false;
		}
		if($('#district').val() == ''){
			layer.msg('地址不能为空', {icon: 1,time:1500,shade: 0.1})
			return false;
		}
		if($('#cr_time').val()== ''){
			layer.msg('生产时间不能为空', {icon: 1,time:1500,shade: 0.1})
			return false;
		}
		if($('#num').val()== ''){
			layer.msg('预产量不能为空', {icon: 1,time:1500,shade: 0.1})
			return false;
		}
		if(pic_d == ""){
			layer.msg('请上传图片', {icon: 1,time:1500,shade: 0.1})
			return false;
		}
	$.ajax({
		type:"post",
		url:APP.api_url + "goods/cre_goods",
		data:{
			id:member['id'],
			name:$('#name').val(),
			type_id:$("#type").val(),
			ztype_id:$("#ztype").val(),
			price:$('#price').val(),
			address:$('#district').val(),
			cr_time:$('#cr_time').val(),
			num:$('#num').val(),
			img:pic_d,
			images:images,
			unit:$('#unit').val()
		},
		dataType:'jsonp',
		success:function(data){
			layer.msg(data.msg, {icon: 1,time:1500,shade: 0.1}, function(index){
                    window.location.href="../goods/spedit.html";
                   });
		},
	
	});

}
</script>